//
//  LSRTabBarController.m
//  BaiSiProject
//
//  Created by lshenrong on 16/7/3.
//  Copyright © 2016年 lshenrong. All rights reserved.
//

#import "LSRTabBarController.h"
#import "LSRNavController.h"
#import "LSREssenceViewController.h"
#import "LSRFriendTrendViewController.h"
#import "LSRMeTableController.h"
#import "LSRNewViewController.h"
#import "LSRPublishViewController.h"

#import "UIImage+image.h"




@interface LSRTabBarController ()

@property(weak,nonatomic)UIButton *publishButton;

@end

@implementation LSRTabBarController


-(UIButton *)publishButton
{
    if (!_publishButton)
    {
        
         //自定义发布按钮
        UIButton *publishButton=[UIButton buttonWithType:UIButtonTypeCustom];
        
        
        [publishButton setImage:[UIImage imageOriginalWithName:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setImage:[UIImage imageOriginalWithName:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        
        //按钮尺寸和图片自适应
        [publishButton sizeToFit];
        
        [self.tabBar addSubview:publishButton];

        _publishButton=publishButton;
    
    
    }




    return _publishButton;

}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    //添加所有子控制器
    [self addChildVC];
  
    //设置tabBar
    [self setTabBar];
    
    self.publishButton.center=CGPointMake(self.tabBar.bounds.size.width * 0.5,self.tabBar.bounds.size.height * 0.5 );
    

    
 

}

+(void)load
{
   
    NSLog(@"%s",__func__);
    
    //如何拿到所有的abBarItem
    UITabBarItem *tabBarItem=[UITabBarItem appearance];
    
//    NSDictionary *dict = [NSDictionary dictionary];
    //这里需要用可变自动，用NSDictionary报找不到相关方法的错误
    
     NSMutableDictionary *dict=[NSMutableDictionary dictionary];
    
    dict[NSForegroundColorAttributeName]=[UIColor blackColor];
    
    [tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    // 设置正常状态下文字字体(设置字体需要在nomal状态下，设置字体颜色不需要)
    NSMutableDictionary *attrNor = [NSMutableDictionary dictionary];
    
    attrNor[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    [tabBarItem setTitleTextAttributes:attrNor forState:UIControlStateNormal];
  


}

-(void)setTabBar

{
        //精华按钮
    UIViewController *VC0= self.childViewControllers[0];
    VC0.tabBarItem.title=@"精华";
   [VC0.tabBarItem setImage:[UIImage imageOriginalWithName:@"tabBar_essence_icon"]];
   [VC0.tabBarItem setSelectedImage:[UIImage imageOriginalWithName:@"tabBar_essence_click_icon"]];
    
    //新帖按钮
    UIViewController *VC1= self.childViewControllers[1];
    VC1.tabBarItem.title=@"新帖";
    [VC1.tabBarItem setImage:[UIImage imageOriginalWithName:@"tabBar_new_icon"]];
    [VC1.tabBarItem setSelectedImage:[UIImage imageOriginalWithName:@"tabBar_new_click_icon"]];
    


       //发布按钮
    UIViewController *VC2= self.childViewControllers[2];
//    VC2.tabBarItem.title=@"发布";
    VC2.tabBarItem.imageInsets=UIEdgeInsetsMake(7, 0, -7, 0);
    VC2.tabBarItem.enabled=NO;

    [VC2.tabBarItem setImage:[UIImage imageOriginalWithName:@"tabBar_publish_icon"]];
    [VC2.tabBarItem setSelectedImage:[UIImage imageOriginalWithName:@"tabBar_publish_click_icon"]];
    
    //关注按钮
    UIViewController *VC3= self.childViewControllers[3];
    VC3.tabBarItem.title=@"关注";
    [VC3.tabBarItem setImage:[UIImage imageOriginalWithName:@"tabBar_friendTrends_icon"]];
    [VC3.tabBarItem setSelectedImage:[UIImage imageOriginalWithName:@"tabBar_friendTrends_click_icon"]];
    


    
    //我的按钮
    UIViewController *VC4= self.childViewControllers[4];
    VC4.tabBarItem.title=@"我的";
    [VC4.tabBarItem setImage:[UIImage imageOriginalWithName:@"tabBar_me_icon"]];
    [VC4.tabBarItem setSelectedImage:[UIImage imageOriginalWithName:@"tabBar_me_click_icon"]];
    

}


-(void)addChildVC

{    //注意：在外界设置控制器的颜色会导致控制器提前加载，最好是在各自控制器的ViewDidLoad加载
   //精华
    LSREssenceViewController *essenceVC=[[LSREssenceViewController alloc] init];
    
//    essenceVC.view.backgroundColor=[UIColor yellowColor];
    
    LSRNavController *navVC0=[[ LSRNavController alloc] initWithRootViewController:essenceVC];
    

    [self addChildViewController:navVC0];
    
    //新帖
    LSRNewViewController *newVC=[[LSRNewViewController alloc] init];
    
//    newVC.view.backgroundColor=[UIColor blueColor];
    
    LSRNavController *navVC3=[[ LSRNavController alloc] initWithRootViewController:newVC];
    
    [self addChildViewController:navVC3];
    
    //发布
    LSRPublishViewController *publishVC=[[LSRPublishViewController alloc] init];
    
//    publishVC.view.backgroundColor=[UIColor brownColor];
    
    LSRNavController *navVC4=[[ LSRNavController alloc] initWithRootViewController:publishVC];
    
    [self addChildViewController:navVC4];
    
    
    
    //关注
    LSRFriendTrendViewController *friendTVC=[[LSRFriendTrendViewController alloc] init];
    
//    friendTVC.view.backgroundColor=[UIColor redColor];
    
    LSRNavController *navVC1=[[ LSRNavController alloc] initWithRootViewController:friendTVC];
    
    [self addChildViewController:navVC1];
    
    
    //我的
//    LSRMeTableController *meVC=[[LSRMeTableController alloc] init];
    
    UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:@"LSRMeTableController" bundle:nil];
    LSRMeTableController *meVC=[storyBoard instantiateInitialViewController];
    
//    meVC.view.backgroundColor=[UIColor orangeColor];
    
    LSRNavController *navVC2=[[ LSRNavController alloc] initWithRootViewController:meVC];
    
    [self addChildViewController:navVC2];
    

    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
